<template>
  <div id="app">
    <h1>根组件{{ $store.state.num }}</h1>
    <input type="text" v-model="$store.state.num" />
    <!-- v-model 接收的是一个值 -->
    <!-- <add-item  v-model="num"></add-item> -->
    <add-item></add-item>
    <hr />
    <!-- <sub-item :getNum='num' @sub="sub"></sub-item> -->
    <sub-item></sub-item>
    {{ test }} {{ test }} {{ test }} {{ test }} {{ test }} {{ test }}
  </div>
</template>

<script>
import AddItem from './components/AddItem.vue'
import SubItem from './components/SubItem.vue'
import { mapState } from 'vuex'
export default {
  name: 'app',
  // data:function(){
  //   return {
  //     num:10
  //   }
  // },
  components: {
    AddItem,
    SubItem
  },
  methods: {
    sub(val) {
      this.num = val
    }
  },
  computed: {
    // ...mapState(['test']),
    ...mapState({
      test: function (state) {
        return state.test + '靓女'
      }
    })
    // test(){
    //   return this.$store.state.test;
    // }
  }
}
</script>

<style>
#app {
  width: 300px;
  margin: 20px auto;
  border: 1px solid #ccc;
  padding: 4px;
}
</style>
